package com.airnewslinkosky.ticket.ui.flight;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.airnewslinkosky.ticket.R;
import com.airnewslinkosky.ticket.adapter.FlyListViewExpandAdapter;
import com.airnewslinkosky.ticket.model.CabinItem;
import com.airnewslinkosky.ticket.model.Flight;
import com.airnewslinkosky.ticket.model.FlightInfo;
import com.airnewslinkosky.ticket.model.FlightRestrict;
import com.airnewslinkosky.ticket.model.SearchFlight;
import com.airnewslinkosky.ticket.net.WebAccessor;
import com.airnewslinkosky.ticket.ui.BaseActivity;
import com.airnewslinkosky.ticket.util.AddrUtil;
import com.airnewslinkosky.ticket.util.DateUtil;
import com.airnewslinkosky.ticket.util.FlyUtil;
import com.airnewslinkosky.ticket.util.StringUtil;
import com.mobclick.android.MobclickAgent;

public class FlyRoundList extends BaseActivity implements OnClickListener {
	public static List<FlightInfo> flist;
	
	public static FlightInfo firstFlight;//去程 
	public static FlightInfo flight;//回程
	
	public static FlightRestrict flightRestrict;
	
	public final int NORESULT = 1;
	public final int SEARCH_ERROR=2;
	public final int SUCCESS=3;
	public FlyListViewExpandAdapter sa;
	public ExpandableListView lv;
	private TextView mTitleInfo,mResule,mTitleEndInfo,titleTipInfo;
	List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
	List<Map<String, Object>> data2 = new ArrayList<Map<String, Object>>();
	FlyUtil flyUtil;
	AddrUtil addrUtil;
	private ProgressDialog progressDialog = null;
	public static SearchFlight searchFlight;
	private ImageView backBut;
	private Button mBtnPre;
	private Button mBtnNext;
	private Button mBtnTimeSort,mBtnPriceSort;
	public  final int SORT_DIALOG_ID = 9;
	
	public static FlightInfo singleFlight;
	
    List<Map<String, Object>> parentList = new ArrayList<Map<String,Object>>();
    List<Map<String, Object>> parentList2 = new ArrayList<Map<String,Object>>();
    // child list
    List<List<Map<String, Object>>> allChildList = new ArrayList<List<Map<String,Object>>>();
    List<List<Map<String, Object>>> allChildList2 = new ArrayList<List<Map<String,Object>>>();
    //是否点击了价格排序
    private boolean isSorePrice=false;  
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.fly);
		// 删除窗口背景
        getWindow().setBackgroundDrawable(null);
		activityList.add(this);
		
		lv = (ExpandableListView) findViewById(R.id.flylist);
		lv.setGroupIndicator(null);
        
        //点击其他价格项的事件
        lv.setOnChildClickListener(new ExpandableListView.OnChildClickListener(){
        	public boolean onChildClick(ExpandableListView parent,View v,int groupPosition,int childPosition,
        	long id){
	        	ExpandableListAdapter adapter = parent.getExpandableListAdapter();
	        	Map<String, Object> childMap = (Map<String, Object>)adapter.getChild(groupPosition,childPosition);
	        	
	        	Map<String, Object> item = (Map<String, Object>) lv.getAdapter().getItem(groupPosition);
	    		final FlightInfo fInfo = (FlightInfo)item.get("finfo");
	    		List<CabinItem> cabinlist = fInfo.cabinItems;
	    		if(cabinlist!=null&&cabinlist.size()>0){
	            	CabinItem cabinItem= cabinlist.get(0);
	            	cabinItem.price = ((String)childMap.get("price")).replace("净价:", "").replace("元", "");
	            	cabinItem.seat = (String)childMap.get("seat");
	            	cabinItem.cabinPrice = ((String)childMap.get("cabinPrice")).replace("票价:", "").replace("元", "");
	            	cabinItem.baseCabin = (String)childMap.get("baseCabinRealValue");
	    		}
	    		
	    		parentClick(groupPosition);
	    		
	        	return false;
        	}
        });
        
		mTitleInfo =(TextView)findViewById(R.id.title_info);
		mResule =(TextView)findViewById(R.id.title_result);
		mTitleEndInfo =(TextView)findViewById(R.id.title_end_info);
		titleTipInfo =(TextView)findViewById(R.id.title_tip_info);
		
		backBut = (ImageView) findViewById(R.id.backBut);
		backBut.setOnClickListener(this);
		
		flyUtil = new FlyUtil(this);
		flyUtil.initCarrier();
		addrUtil = new AddrUtil(this);
		
		renderData();

		mBtnNext = (Button) findViewById(R.id.btn_next);
		mBtnPre = (Button) findViewById(R.id.btn_pre);
		mBtnTimeSort = (Button) findViewById(R.id.btn_byTime);
		mBtnPriceSort = (Button) findViewById(R.id.btn_byPrice);
		mBtnNext.setOnClickListener(this);
		mBtnPre.setOnClickListener(this);
		mBtnTimeSort.setOnClickListener(this);
		mBtnPriceSort.setOnClickListener(this);
	}
	private void parentClick(int position) {
		Map<String, Object> item = (Map<String, Object>) lv.getAdapter().getItem(position);
		final FlightInfo fInfo = (FlightInfo)item.get("finfo");
		progressDialog = ProgressDialog.show(this, "请稍等...", "查询机票明细...",true);
		final Thread thread = new Thread() {
			public void run() {
				FlightRestrict returnFlightRestrict =  WebAccessor.getFlightRestrict(FlyRoundList.this,fInfo);
				if (progressDialog.isShowing()) {
					if (returnFlightRestrict== null) {
						Message msg = new Message();
						msg.what = NORESULT;
						myHandler.sendMessage(msg);
					}else if(!"0".equals(returnFlightRestrict.resultcode)){
						Message msg = new Message();
						msg.what = SEARCH_ERROR;
						msg.obj = returnFlightRestrict.message;
						myHandler.sendMessage(msg);
					}else{
						System.out.println("enter into detail...............");
						Intent intent = new Intent();
			    		intent.setClass(FlyRoundList.this, FlyRoundDetail.class);
			    		FlyRoundDetail.firstFlight = firstFlight;
			    		FlyRoundDetail.flight = fInfo;
			    		intent.putExtra("ftype", "round");
			    		FlyRoundDetail.searchFlight = searchFlight;
			    		FlyRoundDetail.flightRestrict = flightRestrict;
			    		FlyRoundDetail.returnFlightRestrict = returnFlightRestrict;
			    		FlyRoundDetail.flist = flist;
			    		
			    		startActivity(intent);
			    		
					}
					progressDialog.dismiss();
				}
			}
		};
		progressDialog.setCancelable(true);
		thread.start();
	}
	 
	public void renderData(){
		parentList.clear();
		allChildList.clear();
		isSorePrice = false;
		for (int i = 0; i < flist.size(); i++) {
			Map<String, Object> map = new HashMap<String, Object>();
			FlightInfo f = flist.get(i);
			map.put("airline", flyUtil.getName(f.airline));
			map.put("departureTime",StringUtil.getTime(f.departureTime));
			map.put("arrivalTime", StringUtil.getTime(f.arrivalTime));
			map.put("planeType", "机型:" + f.planeType);
			map.put("flightNo", f.flightNo);
			String food = f.isFood == 0 ? "有餐食" : "无餐食";
			map.put("airLogo", flyUtil.getLogIndex(f.airline)); 
			map.put("isFood", food);
			List<CabinItem> items = f.cabinItems;
            if(items!=null&&items.size()>0){			
            	CabinItem cabinItem = items.get(0);//取最低价格//items.size()-1
				String priceFormat = cabinItem.price.indexOf(".00") != -1 ? cabinItem.price.substring(0, cabinItem.price.indexOf(".00")) : cabinItem.price;
            	String ibePaymentFormat = cabinItem.ibePayment.indexOf(".00") != -1 ? cabinItem.ibePayment.substring(0, cabinItem.ibePayment.indexOf(".00")) : cabinItem.ibePayment;
            	String cabinPriceFormat = cabinItem.cabinPrice.indexOf(".00") != -1 ? cabinItem.cabinPrice.substring(0, cabinItem.cabinPrice.indexOf(".00")) : cabinItem.cabinPrice;
            	Float priceCal = Float.parseFloat(cabinPriceFormat) - Float.parseFloat(ibePaymentFormat);
            	
            	map.put("cabinPrice", "￥" + cabinPriceFormat + "元");
				map.put("price", "￥" + String.valueOf(priceCal)+ "元   ");
				map.put("basePrice", "返"  + ibePaymentFormat + "元");
				
				map.put("discount","("+FlyUtil.parseDiscount(cabinItem.discount)+")");
				
				map.put("seat",  cabinItem.seat);
				map.put("baseCabin", " " + cabinItem.baseCabin + flyUtil.getJClassName(cabinItem.baseCabin) + " ");
            }else{
            	map.put("cabinPrice", "");
				map.put("discount","");
            }
            
            List<Map<String, Object>> childList = new ArrayList<Map<String,Object>>();
            //取其他价格
            if(items!=null&&items.size()>0){
            	for(int s = 0; s < items.size(); s++){
            		CabinItem cabinItem= items.get(s);
            		Map<String, Object> childData = new HashMap<String, Object>();
            		String priceFormat = cabinItem.price.indexOf(".00") != -1 ? cabinItem.price.substring(0, cabinItem.price.indexOf(".00")) : cabinItem.price;
                	String ibePaymentFormat = cabinItem.ibePayment.indexOf(".00") != -1 ? cabinItem.ibePayment.substring(0, cabinItem.ibePayment.indexOf(".00")) : cabinItem.ibePayment;
                	String cabinPriceFormat = cabinItem.cabinPrice.indexOf(".00") != -1 ? cabinItem.cabinPrice.substring(0, cabinItem.cabinPrice.indexOf(".00")) : cabinItem.cabinPrice;
                	Float priceCal = Float.parseFloat(cabinPriceFormat) - Float.parseFloat(ibePaymentFormat);
                	
                	childData.put("cabinPrice", "￥" + cabinPriceFormat + "元");
                	childData.put("price", "￥" + String.valueOf(priceCal)+ "元   ");
                	childData.put("basePrice", "返"  + ibePaymentFormat + "元");
                	
                	childData.put("discount","("+FlyUtil.parseDiscount(cabinItem.discount)+")");
                	
                	childData.put("seat",  cabinItem.seat);
                	childData.put("baseCabin", " " + cabinItem.baseCabin + flyUtil.getJClassName(cabinItem.baseCabin) + " ");
                	childData.put("baseCabinRealValue", cabinItem.baseCabin);
                	childList.add(childData);
            	}
            	allChildList.add(childList);
            }
            
        	map.put("arrival", addrUtil.getCityByCode(f.arrival).getAirName());
        	map.put("departure",addrUtil.getCityByCode(f.departure).getAirName());
            
            map.put("finfo", f);
            parentList.add(map);
		}
		
		sa = new FlyListViewExpandAdapter(FlyRoundList.this,parentList,allChildList);
		lv.setAdapter(sa);
		sa.notifyDataSetChanged();
		
		StringBuffer sb = new StringBuffer().append("回程  ").append(searchFlight.departureDate).append(" ").append(searchFlight.fcity).append("→").append(searchFlight.tcity).append(" 共");
		mTitleInfo.setText(sb);
		mResule.setText(String.valueOf(flist.size()));
		mTitleEndInfo.setText("个");
		titleTipInfo.setText("温馨提示：点击某条记录查看其所有价格信息。");
	}

	public boolean compareTime(String str1, String str2) {
		int n1 = Integer.parseInt(str1.substring(0, 2) + str1.substring(3, 5));
		int n2 = Integer.parseInt(str2.substring(0, 2) + str2.substring(3, 5));
		return n1 < n2;
	}
	public void initByPrice() {
		parentList2.clear();
		allChildList2.clear();
		isSorePrice = true;
		for (int i = 0; i < flist.size(); i++) {
			Map<String, Object> map = new HashMap<String, Object>();
			FlightInfo f = flist.get(i);
            map.put("airline", flyUtil.getName(f.airline));
            map.put("departureTime",StringUtil.getTime(f.departureTime));
			map.put("arrivalTime", StringUtil.getTime(f.arrivalTime));
			map.put("planeType", "机型:" + f.planeType);
			map.put("flightNo", f.flightNo);
			String food = f.isFood == 0 ? "有餐食" : "无餐食";
			map.put("airLogo", flyUtil.getLogIndex(f.airline)); 
			map.put("isFood", food);
			List<CabinItem> items = f.cabinItems;
			
			String cabinPrice="0";
            if(items!=null&&items.size()>0){
            	CabinItem cabinItem= items.get(0);
            	String priceFormat = cabinItem.price.indexOf(".00") != -1 ? cabinItem.price.substring(0, cabinItem.price.indexOf(".00")) : cabinItem.price;
            	String ibePaymentFormat = cabinItem.ibePayment.indexOf(".00") != -1 ? cabinItem.ibePayment.substring(0, cabinItem.ibePayment.indexOf(".00")) : cabinItem.ibePayment;
            	String cabinPriceFormat = cabinItem.cabinPrice.indexOf(".00") != -1 ? cabinItem.cabinPrice.substring(0, cabinItem.cabinPrice.indexOf(".00")) : cabinItem.cabinPrice;
            	Float priceCal = Float.parseFloat(cabinPriceFormat) - Float.parseFloat(ibePaymentFormat);
            	
            	map.put("cabinPrice", "￥" + cabinPriceFormat + "元");
				map.put("price", "￥" + String.valueOf(priceCal)+ "元   ");
				map.put("basePrice", "返"  + ibePaymentFormat + "元");
				map.put("priceFloat", priceCal);
				map.put("cabinPriceFloat", cabinPriceFormat);
            	
				map.put("discount","("+FlyUtil.parseDiscount(cabinItem.discount)+")");
				
				cabinPrice = cabinPriceFormat;
				map.put("seat",  cabinItem.seat);
				map.put("baseCabin", " " + cabinItem.baseCabin + flyUtil.getJClassName(cabinItem.baseCabin) + " ");
            }else{
            	map.put("cabinPrice", "");
				map.put("discount","");
            }
            map.put("arrival", addrUtil.getCityByCode(f.arrival).getAirName());
        	map.put("departure",addrUtil.getCityByCode(f.departure).getAirName());
        	
            map.put("finfo", f);
			int j = 0;
			List<Map<String, Object>> childSoreList = new ArrayList<Map<String,Object>>();
			
			for (; j < parentList2.size(); j++) {
				String jcabinPrice = (String)parentList2.get(j).get("cabinPriceFloat");
				jcabinPrice = "".equals(jcabinPrice)?"0":jcabinPrice;
				
				if(Float.parseFloat(cabinPrice)<Float.parseFloat(jcabinPrice)){
					parentList2.add(j, map);
					List<CabinItem> itemsSore = f.cabinItems;
		            //取其他价格
		            if(itemsSore!=null&&itemsSore.size()>0){
		            	for(int s = 0; s < itemsSore.size(); s++){
		            		CabinItem cabinItem= itemsSore.get(s);
		            		Map<String, Object> childData = new HashMap<String, Object>();
		            		String priceFormat = cabinItem.price.indexOf(".00") != -1 ? cabinItem.price.substring(0, cabinItem.price.indexOf(".00")) : cabinItem.price;
		                	String ibePaymentFormat = cabinItem.ibePayment.indexOf(".00") != -1 ? cabinItem.ibePayment.substring(0, cabinItem.ibePayment.indexOf(".00")) : cabinItem.ibePayment;
		                	String cabinPriceFormat = cabinItem.cabinPrice.indexOf(".00") != -1 ? cabinItem.cabinPrice.substring(0, cabinItem.cabinPrice.indexOf(".00")) : cabinItem.cabinPrice;
		                	Float priceCal = Float.parseFloat(cabinPriceFormat) - Float.parseFloat(ibePaymentFormat);
		                	
		                	childData.put("cabinPrice", "￥" + cabinPriceFormat + "元");
		                	childData.put("price", "￥" + String.valueOf(priceCal)+ "元   ");
		                	childData.put("basePrice", "返"  + ibePaymentFormat + "元");
		                	
		                	childData.put("discount","("+FlyUtil.parseDiscount(cabinItem.discount)+")");
		                	
		                	childData.put("seat",  cabinItem.seat);
		                	childData.put("baseCabin", " " + cabinItem.baseCabin + flyUtil.getJClassName(cabinItem.baseCabin) + " ");
		                	childData.put("baseCabinRealValue", cabinItem.baseCabin);
		                	childSoreList.add(childData);
		            	}
		            	allChildList2.add(j,childSoreList);
		            }
					break;
				}
			}
			if (j == parentList2.size()) {
				parentList2.add(map);
				List<CabinItem> itemsSore = ((FlightInfo)map.get("finfo")).cabinItems;
				//取其他价格
	            if(itemsSore!=null&&itemsSore.size()>0){
	            	for(int s = 0; s < itemsSore.size(); s++){
	            		CabinItem cabinItem= itemsSore.get(s);
	            		Map<String, Object> childData = new HashMap<String, Object>();
	                	String priceFormat = cabinItem.price.indexOf(".00") != -1 ? cabinItem.price.substring(0, cabinItem.price.indexOf(".00")) : cabinItem.price;
	                	String ibePaymentFormat = cabinItem.ibePayment.indexOf(".00") != -1 ? cabinItem.ibePayment.substring(0, cabinItem.ibePayment.indexOf(".00")) : cabinItem.ibePayment;
	                	String cabinPriceFormat = cabinItem.cabinPrice.indexOf(".00") != -1 ? cabinItem.cabinPrice.substring(0, cabinItem.cabinPrice.indexOf(".00")) : cabinItem.cabinPrice;
	                	Float priceCal = Float.parseFloat(cabinPriceFormat) - Float.parseFloat(ibePaymentFormat);
	                	
	                	childData.put("cabinPrice", "￥" + cabinPriceFormat + "元");
	                	childData.put("price", "￥" + String.valueOf(priceCal)+ "元   ");
	                	childData.put("basePrice", "返"  + ibePaymentFormat + "元");
	                	
	                	childData.put("discount","("+FlyUtil.parseDiscount(cabinItem.discount)+")");
	                	
	                	childData.put("seat",  cabinItem.seat);
	                	childData.put("baseCabin", " " + cabinItem.baseCabin + flyUtil.getJClassName(cabinItem.baseCabin) + " ");
	                	childData.put("baseCabinRealValue", cabinItem.baseCabin);
	                	childSoreList.add(childData);
	            	}
	            	allChildList2.add(childSoreList);
	            }
			}
			
			sa = new FlyListViewExpandAdapter(FlyRoundList.this,parentList2,allChildList2);
			lv.setAdapter(sa);
			sa.notifyDataSetChanged();
			
			StringBuffer sb = new StringBuffer().append("回程  ").append(searchFlight.departureDate).append(" ").append(searchFlight.fcity).append("→").append(searchFlight.tcity).append(" 共");
			mTitleInfo.setText(sb);
			mResule.setText(String.valueOf(flist.size()));
			mTitleEndInfo.setText("个");
			titleTipInfo.setText("温馨提示：点击某条记录查看其所有价格信息。");
			
		}
	}


	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.backBut:
			onBackPressed();
			break;
		case R.id.btn_pre:
			String date = searchFlight.departureDate;
			searchFlight.departureDate = DateUtil.addDay(date,-1);
			getData();
			break;
		case R.id.btn_next:
			String date1 = searchFlight.departureDate;
			searchFlight.departureDate = DateUtil.addDay(date1,1);
			if(DateUtil.getMargin(searchFlight.departureDate,DateUtil.getDate())!=0){
				mBtnPre.setEnabled(true);
			}
			getData();
			break;
		case R.id.btn_byTime:
			renderData();
			sa = new FlyListViewExpandAdapter(FlyRoundList.this,parentList,allChildList);
			lv.setAdapter(sa);
			sa.notifyDataSetChanged();
			break;
		case R.id.btn_byPrice:
			initByPrice();
			sa = new FlyListViewExpandAdapter(FlyRoundList.this, parentList2,allChildList2);
			lv.setAdapter(sa);
			sa.notifyDataSetChanged();
			break;
		}
	}

	public Handler myHandler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case NORESULT:
				Toast.makeText(FlyRoundList.this, "未找到符合条件的航班", Toast.LENGTH_LONG)
						.show();
				parentList.clear();
				sa.notifyDataSetChanged();
				String fcity = getIntent().getStringExtra("fcity");
				String tcity = getIntent().getStringExtra("tcity");
				
				StringBuffer sb = new StringBuffer().append("去程  ").append(searchFlight.departureDate).append(" ").append(fcity).append("→").append(tcity).append(" 共");
				mTitleInfo.setText(sb);
				if(flist==null){
					mResule.setText("0");
				}
				mTitleEndInfo.setText("个");
				break;
			case SEARCH_ERROR:
				Toast.makeText(FlyRoundList.this, (String)msg.obj, Toast.LENGTH_LONG)
				.show();
				parentList.clear();
				sa.notifyDataSetChanged();
				String fcity2 = getIntent().getStringExtra("fcity");
				String tcity2 = getIntent().getStringExtra("tcity");
				
				StringBuffer sb2 = new StringBuffer().append("回程  ").append(searchFlight.departureDate).append(" ").append(fcity2).append("→").append(tcity2).append(" 共");
				mTitleInfo.setText(sb2);
				if(flist==null){
				mResule.setText("0");
				}
				mTitleEndInfo.setText("个");
				break;
			case SUCCESS:
				sa.notifyDataSetChanged();
				if(isSorePrice){
					initByPrice();
				} else {
					renderData();
				}
				break;
			}
			StringBuffer sb = new StringBuffer().append(searchFlight.departureDate).append("   ").append(searchFlight.fcity).append("至").append(searchFlight.tcity);
			mTitleInfo.setText(sb);
			super.handleMessage(msg);
		}
	};
	
	public void getData(){
		progressDialog = ProgressDialog.show(this, "请稍等...", "查询机票中...",
				true);
		final Thread thread1 = new Thread() {
			public void run() {
			
				Flight flight =  WebAccessor.GetFlightTicket(FlyRoundList.this,searchFlight);
				
				if (progressDialog.isShowing()) {
					if (flight== null) {
						Message msg = new Message();
						msg.what = NORESULT;
						flist = null;
						myHandler.sendMessage(msg);
					}else if(!"0".equals(flight.resultcode)){
						Message msg = new Message();
						msg.what = SEARCH_ERROR;
						flist = null;
						msg.obj = flight.message;
						myHandler.sendMessage(msg);
					}else {
						Message msg = new Message();
						msg.what = SUCCESS;
						msg.obj = flight.flightInfos;
						flist = flight.flightInfos;
						myHandler.sendMessage(msg);
					}
					progressDialog.dismiss();
				}
			}
		};
		progressDialog.setCancelable(true);
		thread1.start();
	}
	
	@Override
	protected Dialog onCreateDialog(int id) {
		switch (id) {
	    case SORT_DIALOG_ID:
	    	 return new AlertDialog.Builder(FlyRoundList.this)
             .setTitle("请选择")
             .setItems(R.array.sort_list, new DialogInterface.OnClickListener() {
                 public void onClick(DialogInterface dialog, int which) {
                	 if (which == 0) {
                		 renderData();
                		 sa = new FlyListViewExpandAdapter(FlyRoundList.this, parentList,allChildList);
                		 sa.notifyDataSetChanged();
             			 lv.setAdapter(sa);
                	 }else {
                		 initByPrice();
                		 sa = new FlyListViewExpandAdapter(FlyRoundList.this, parentList2,allChildList2);
                		 sa.notifyDataSetChanged();
             			 lv.setAdapter(sa);
					 }
                 }
             })
             .create();
		default:
			return null;
		}
	}
	@Override
	public void onBackPressed() {
		Intent intent = new Intent();
		intent.setClass(this, FlightRoundQuery.class);
		intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		startActivityIfNeeded(intent, -1);
	}
	
	public void onResume() {     
		super.onResume();     
		MobclickAgent.onResume(this); 
	}  
	
	public void onPause() {     
		super.onPause();     
		MobclickAgent.onPause(this); 
	}  
}